package hhm.android.main.shoeSizeHistory

//class ExpandedableListActivity : SBBaseActivity() {
//
//    lateinit var dataBinding: ActivityShoeSizeHistoryListBinding
//    lateinit var adapter: ExpandedableListAdapter
//    lateinit var viewModel: ExpandedableListViewModel
//
//    private var group = ArrayList<ListHistoryModel>()
//    private var child = ArrayList<ArrayList<ListHistoryChildModel>>()
//    private var childId: Int = -1
//
//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//        setTitleWhiteAndTextBlank()
//        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_shoe_size_history_list)
//        initTitle(getString(R.string.history_list))
//        viewModel = ViewModelProvider(this).get(ExpandedableListViewModel::class.java)
//        dataBinding.viewModel = viewModel
//        dataBinding.lifecycleOwner = this
//
//        val d = Date()
//        val sdf = SimpleDateFormat("yyyy/MM")
//        val string = sdf.format(d)
//        val times = string.split("/")
//        viewModel.year.value = times[0].toInt()
//        viewModel.month.value = times[1].toInt()
//        dataBinding.activityShoeSizeHistoryListTime.text = viewModel.month.value.toString() + "月"
//
//        childId = intent.getIntExtra(KeyString.childId, -1)
//
//        adapter = ExpandedableListAdapter(group, child, viewModel.pageState.value!!)
//        dataBinding.activityShoeSizeHistoryListElv.setAdapter(adapter)
//
//        viewModel.pageState.observe(this, {
//            if (it == viewModel.PAGE_WATCH) {
//                dataBinding.activityShoeSizeHistoryListAllSelectLl.visibility = View.GONE
//                dataBinding.activityShoeSizeHistoryListSpace3.visibility = View.GONE
//                dataBinding.topBackIv.setImageResource(R.mipmap.arrow_back)
//                dataBinding.topTitle.text = getString(R.string.history_list)
//                adapter.pageState = viewModel.PAGE_WATCH
//            } else if (it == viewModel.PAGE_SELECT) {
//                dataBinding.activityShoeSizeHistoryListAllSelectLl.visibility = View.VISIBLE
//                dataBinding.activityShoeSizeHistoryListSpace3.visibility = View.VISIBLE
//                dataBinding.topBackIv.setImageResource(R.mipmap.x)
//                adapter.pageState = viewModel.PAGE_SELECT
//                changeTitle()
//            }
//            adapter.notifyDataSetChanged()
//        })
//        viewModel.selectListNum.observe(this, {
//            if (viewModel.pageState.value == viewModel.PAGE_SELECT) {
//                changeTitle()
//            }
//        })
//
//        dataBinding.topBack.setOnClickListener {
//            if (viewModel.pageState.value == viewModel.PAGE_WATCH) {
//                finish()
//            } else {
//                viewModel.pageState.value = viewModel.PAGE_WATCH
//                viewModel.selectList.value?.forEach {
//                    it.select = false
//                }
//                viewModel.selectList.value!!.clear()
//                viewModel.selectListNum.value = viewModel.selectList.value!!.size
//                adapter.notifyDataSetChanged()
//            }
//        }
//
//        dataBinding.activityShoeSizeHistoryListElv.setOnChildClickListener { parent, v, groupPosition, childPosition, id ->
//            if (viewModel.pageState.value == viewModel.PAGE_SELECT) {
//                val vh = v?.tag as ExpandedableChildViewHolder
//                if (child[groupPosition][childPosition].select) {
//                    child[groupPosition][childPosition].select = false
//                    vh.select.setImageResource(R.mipmap.list_history_unselect)
//                    viewModel.selectList.value!!.remove(child[groupPosition][childPosition])
//                    viewModel.selectListNum.value = viewModel.selectList.value!!.size
//                } else {
//                    child[groupPosition][childPosition].select = true
//                    vh.select.setImageResource(R.mipmap.list_history_select)
//                    viewModel.selectList.value!!.add(child[groupPosition][childPosition])
//                    viewModel.selectListNum.value = viewModel.selectList.value!!.size
//                }
//                val outSize = child.size
//                var sum = 0
//                for (i in 0 until outSize) {
//                    sum += child[i].size
//                }
//                if (viewModel.selectListNum.value == sum) {
//                    dataBinding.activityShoeSizeHistoryListAllSelectIv.setImageResource(R.mipmap.list_history_all_not_select)
//                    dataBinding.activityShoeSizeHistoryListAllSelectTv.text = getString(R.string.all_not_select)
//                    adapter.notifyDataSetChanged()
//                } else {
//                    dataBinding.activityShoeSizeHistoryListAllSelectIv.setImageResource(R.mipmap.list_history_all_select)
//                    dataBinding.activityShoeSizeHistoryListAllSelectTv.text = getString(R.string.all_select)
//                    adapter.notifyDataSetChanged()
//                }
//            }
//            false
//        }
//
//        for (i in 0 until group.size) {
//            dataBinding.activityShoeSizeHistoryListElv.expandGroup(i)
//        }
//        dataBinding.activityShoeSizeHistoryListElv.setOnGroupCollapseListener {
//            dataBinding.activityShoeSizeHistoryListElv.expandGroup(it)
//        }
//
//        dataBinding.activityShoeSizeHistoryListDelete.setOnClickListener {
//            if (viewModel.pageState.value == viewModel.PAGE_WATCH) {
//                viewModel.pageState.value = viewModel.PAGE_SELECT
//            } else {
//                if (viewModel.selectListNum.value!! > 0) {
//                    getSureDialog(this, {
//                        deleteData()
//                    }, content = getString(R.string.sure_delete_data), showTitle = false)
//                }
//            }
//        }
//
//        dataBinding.activityShoeSizeHistoryListAllSelectLl.setOnClickListener {
//            val outSize = child.size
//            var sum = 0
//            for (i in 0 until outSize) {
//                sum += child[i].size
//            }
//            if (viewModel.selectListNum.value == sum) {
//                viewModel.selectList.value?.forEach {
//                    it.select = false
//                }
//                viewModel.selectList.value!!.clear()
//                viewModel.selectListNum.value = viewModel.selectList.value!!.size
//                dataBinding.activityShoeSizeHistoryListAllSelectIv.setImageResource(R.mipmap.list_history_all_select)
//                dataBinding.activityShoeSizeHistoryListAllSelectTv.text = getString(R.string.all_select)
//                adapter.notifyDataSetChanged()
//            } else {
//                viewModel.selectList.value?.forEach {
//                    it.select = false
//                }
//                viewModel.selectList.value!!.clear()
//                for (i in 0 until outSize) {
//                    viewModel.selectList.value!!.addAll(child[i])
//                }
//                viewModel.selectList.value?.forEach {
//                    it.select = true
//                }
//                viewModel.selectListNum.value = viewModel.selectList.value!!.size
//                dataBinding.activityShoeSizeHistoryListAllSelectIv.setImageResource(R.mipmap.list_history_all_not_select)
//                dataBinding.activityShoeSizeHistoryListAllSelectTv.text = getString(R.string.all_not_select)
//                adapter.notifyDataSetChanged()
//            }
//        }
//
//        dataBinding.activityShoeSizeHistoryListSelectMonth.setOnClickListener {
//            DialogUtils.showDatePicBottomView(
//                this,
//                object : GetDateListener {
//                    override fun getDate(date: Date, string: String) {
//                        val times = string.split("/")
//                        viewModel.year.value = times[0].toInt()
//                        viewModel.month.value = times[1].toInt()
//                        dataBinding.activityShoeSizeHistoryListTime.text = viewModel.month.value.toString() + "月"
//                        showLoadingFragment(R.id.activity_shoe_size_history_list_fl)
//                        initData()
//                    }
//                },
//                "yyyy/MM",
//                DateParams.TYPE_YEAR, DateParams.TYPE_MONTH,
//            )
//        }
//        showLoadingFragment(R.id.activity_shoe_size_history_list_fl)
//        initData()
//    }
//
//    private fun changeTitle() {
//        dataBinding.topTitle.text = if (viewModel.selectListNum.value == 0) {
//            "未选择"
//        } else {
//            "已选择 ${viewModel.selectListNum.value} 项"
//        }
//    }
//
//    private fun initData() {
//        if (viewModel.pageState.value == viewModel.PAGE_SELECT) {
//            viewModel.pageState.value = viewModel.PAGE_WATCH
//            viewModel.selectList.value?.clear()
//            viewModel.selectListNum.value = 0
//            dataBinding.activityShoeSizeHistoryListAllSelectIv.setImageResource(R.mipmap.list_history_all_select)
//            dataBinding.activityShoeSizeHistoryListAllSelectTv.text = getString(R.string.all_select)
//        }
//        val r = ListHistoryRequest(viewModel.year.value!!, viewModel.month.value!!, childId, 3)
//        HttpHelper().listHistory(r)?.compose(RxLifecycle.bindUntilEvent(lifecycle(), ActivityEvent.STOP))?.subscribe({
//
//            if (it.size == 0) {
//                showNoDataView()
//                return@subscribe
//            }
//            removeLoadingFragment()
//
//            group.clear()
//            group.addAll(it)
//            child.clear()
//            group.forEach { i ->
//                child.add(i.records)
//            }
//
//            group.forEachIndexed { index, _ ->
//                dataBinding.activityShoeSizeHistoryListElv.expandGroup(index)
//            }
//            adapter.notifyData(group, child)
//
//        }, {
//            removeLoadingFragment()
//            showToast(it.message)
//        })
//    }
//
//    private fun deleteData() {
//        val l = ArrayList<Int>()
//        viewModel.selectList.value?.forEach {
//            l.add(it.id)
//        }
//        val r = ListHistoryDeleteRequest(l, childId, 3)
//        showLoadingFragment(R.id.activity_shoe_size_history_list_fl)
//        HttpHelper().deleteHistory(r)?.compose(RxLifecycle.bindUntilEvent(lifecycle(), ActivityEvent.STOP))?.subscribe({
//            viewModel.selectList.value?.clear()
//            viewModel.selectListNum.value = 0
//            dataBinding.activityShoeSizeHistoryListAllSelectIv.setImageResource(R.mipmap.list_history_all_select)
//            dataBinding.activityShoeSizeHistoryListAllSelectTv.text = getString(R.string.all_select)
//            initData()
//        }, {
//            removeLoadingFragment()
//            showToast(it.message)
//        })
//    }
//}